package pkp;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardGame {

     public static final String[] suits = {"♦","♣","♥","♠"};
    public List<Card> buyCard() {
         List<Card> cardList = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13 ; j++) {
                String suit = suits[i];
                Card card = new Card(suit, j);
                cardList.add(card);
            }
        }
        return cardList;
    }
    public void shuffle(List<Card> cardList) {
        Random random = new Random();
        for (int i = cardList.size()-1; i > 0 ; i--) {
            int index = random.nextInt(i);
            swap(cardList, i,index );
        }
    }
    private static void swap(List<Card> cardList,int i, int j) {
        Card temp = cardList.get(i);
        cardList.set(i,cardList.get(j));
        cardList.set(j,temp);
    }

    public List<List<Card>> getCard(List<Card> cardList,int n,int m) {
//        List<Card> hand1 = new ArrayList<>();
//        List<Card> hand2 = new ArrayList<>();
//        List<Card> hand3 = new ArrayList<>();


//        List<List<Card>> hand = new ArrayList<>();
//        hand.add(hand1);
//        hand.add(hand2);
//        hand.add(hand3);
        List<List<Card>> hand = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            hand.add(new ArrayList<>());
        }

        //抓5轮牌，每轮抓一张牌
        for (int i = 0; i < m ; i++) {
            for (int j = 0; j < n; j++) {
                //怎么揭牌---s删除0下标
               Card card = cardList.remove(0);
               //怎么发牌
               hand.get(j).add(card);
            }
        }
        return hand;
    }
}
